package com.easy.controller;

import com.easy.bean.Orders;
import com.easy.service.OrdersService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("orders")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @PostMapping
    public Result add(@RequestBody Orders orders) {
        Object obj = ordersService.add(orders);
        return Result.success(obj);
    }
    @PutMapping
    public Result edit(@RequestBody Orders orders) {
        Object obj = ordersService.edit(orders);
        return Result.success(obj);
    }
    @DeleteMapping("{order_id}")
    public Result del(@PathVariable("order_id") Integer id) {
            Object obj = ordersService.del(id);
            return Result.success(obj);
    }
    @GetMapping("{order_id}")
    public Result one(@PathVariable("order_id") Integer id){
        Object obj = ordersService.one(id);
        return Result.success(obj);
    }
    @GetMapping("all")
    public Result all(Orders orders){
        Object obj = ordersService.all(orders);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Orders orders){
        //查询一共有多少条数据
        //查询当前页要显示的数据
        //将以上数据封装到page对象中
        ordersService.page(page,orders);
        //返回page对象
        return Result.success(page);
    }
}

